package com.qinghong;

import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

public class DocumentBuilderFactory {
    public static void main(String[] args) throws Exception {
        javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.parse("students.xml");
        XPath xPath = XPathFactory.newInstance().newXPath();
        String title = "/bookstore/book[@category='web'][2]/title";
        String evaluate = (String) xPath.evaluate(title, document, XPathConstants.STRING);
    }
}
